# 定义中间键函数,内部隐藏的五步:
#
# 1 接收到请求
# 2 路由加载匹配视图
# 3 加载模板,执行函数
# 4 异常捕获
# 5 响应


def my_middleware(get_response):
    print("init 初始化中间件")

    def middleware(request, *args, **kwargs):
        print("before request 被调用")
        response = get_response(request, *args, **kwargs)
        print("after response 被调用")
        return response

    return middleware


def my_middleware2(get_response):
    print("init2 初始化中间件")

    def middleware(request, *args, **kwargs):
        print("before request2 被调用")
        response = get_response(request, *args, **kwargs)
        print("after response2 被调用")
        return response

    return middleware